var util = require('../../utils/util.js');
Page({
  data: {
    allEvaluateList: [],
    tabH: ["全部", "好评", "中评", "差评"],
    currentTab: 0,
    requiredHeight: "100vh",
    count_num: 0, //好星数量
    evaluateImg: [], //评价图片
    currentId: 0, //初始化显示tab
    evaluate_type: ""
  },

  onLoad: function() {
    this.intData()
  },
  intData: function() {
    var that = this;
    util.postUrl('goods/evaluate_list', {
      goods_id: 85,
      evaluate_type: that.data.currentId,
      curpage: 1,
      page_num: 9
    }, function(res) {
      for (var key in res.data.datas.list) {
        res.data.datas.list[key].geval_scores
      }
      if (res.data.code == 200) {

        var allEvaluateList = that.data.allEvaluateList;
        var temp = res.data.datas.list

        allEvaluateList[that.data.currentTab] = temp;
        console.log(allEvaluateList);
        that.setData({
          allEvaluateList: allEvaluateList,
          count_num: parseInt(res.data.datas.list[key].geval_scores)
        })

      }
    })
  },
  //点击切换
  clickTab: function(e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current,
        currentId: e.currentTarget.dataset.current
      })
    }
  },
  //滑动切换
  swiperTab: function(e) {
    var that = this;
    var current = e.detail.current;
    that.setData({
      currentTab: e.detail.current
    });
    that.intData()
  }
})